<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8" />
		<title>beginBitmapFill</title>
		<script type="text/javascript" src="../lufylegend-1.7.4.min.js"></script>
	</head>
	<body>
			<div id="legend"></div>
			<script>
				init(50,"legend",800,600,main);
				
				var vertices;
				var indices;
				var uvtData;
				var backLayer;
				var bitmapData,earthBitmapData;
				var rows=20,cols=20;
				var mi=0;
				var imgData = [
					{name:"face",path:"face.jpg"}
				];
				var imglist;
				function main(){
					LLoadManage.load(imgData,null,gameInit);
				}
				function gameInit(result){
					LGlobal.setDebug(true);
					imglist = result;
					bitmapData = new LBitmapData(imglist["face"]);
					earthBitmapData = new LBitmapData(null,0,0,500,400);
					var img = bitmapData.getPixels(new LRectangle(75,50,100,100));
					var rect = new LRectangle(50,100,100,100);
					var rect1 = new LRectangle(150,100,100,100);
					var j=0;
					earthBitmapData.lock();
					earthBitmapData.setPixels(new LRectangle(50,30,50,50),img);
					earthBitmapData.setPixels(new LRectangle(100,30,50,50),img);
					earthBitmapData.setPixels(new LRectangle(150,30,50,50),img);
					earthBitmapData.setPixels(new LRectangle(200,30,50,50),img);
					for(var y=0;y<rect.height;y++){
						for(var x=0;x<rect.width;x++){
							var i = y*4*100+x*4;
							earthBitmapData.setPixel(rect.x+rect.width-x,y+rect.y,[img.data[i],img.data[i+1],img.data[i+2],img.data[i+3]]);
						}
					}
					for(var y=0;y<rect1.height;y++){
						for(var x=0;x<rect1.width;x++){
							var i = y*4*100+x*4;
							earthBitmapData.setPixel(x+rect1.x,y+rect1.y,[img.data[i],img.data[i+1],img.data[i+2],img.data[i+3]]);
						}
					}
					earthBitmapData.unlock();
					
					backLayer = new LSprite();
					addChild(backLayer);
					backLayer.addChild(new LBitmap(earthBitmapData));
					return;
					backLayer = new LSprite();
					backLayer.alpha = 0.2;
					backLayer.rotate = 10;
					backLayer.y = 300;
					addChild(backLayer);
					backLayer.graphics.beginBitmapFill(bitmapData);
					backLayer.graphics.drawRect(1,"#000",[100,100,100,100]);
					
					return;
					backLayer = new LSprite();
					backLayer.alpha = 0.2;
					backLayer.rotate = 10;
					backLayer.y = 300;
					addChild(backLayer);
					backLayer.graphics.beginBitmapFill(bitmapData);
					backLayer.graphics.drawRect(1,"#000",[100,100,100,100]);
					
					
					backLayer = new LSprite();
					backLayer.alpha = 0.5;
					backLayer.scaleX = 0.5;
					addChild(backLayer);
					backLayer.graphics.clear();
					backLayer.graphics.beginBitmapFill(bitmapData);
					backLayer.graphics.drawRect(1,"#000",[100,100,100,100]);
					
					return;
					
					backLayer = new LSprite();
					addChild(backLayer);
					backLayer.graphics.beginBitmapFill(bitmapData);
					backLayer.graphics.drawArc(1,"#000",[150,50,50,0,Math.PI*2]);
					
					backLayer = new LSprite();
					addChild(backLayer);
					backLayer.graphics.clear();
					backLayer.graphics.beginBitmapFill(bitmapData);
					backLayer.graphics.drawVertices(1,"#000",[[120,100],[100,200],[200,150]]);
					
					
					vertices = new Array();
					//在位图上定义了6个点
					vertices.push(0, 0);
					vertices.push(-40, 90);
					vertices.push(0, 200);
					vertices.push(80, 0);
					vertices.push(90, 30);
					vertices.push(70,200);
					vertices.push(130, 10);
					vertices.push(140, 40);
					vertices.push(120,220);
					indices = new Array();
					//这里用之前的6个点将图形分成4个三角形
					indices.push(0, 3, 1);
					indices.push(3, 1, 4);
					indices.push(1, 4, 2);
					indices.push(4, 2, 5);
					indices.push(3, 6, 4);
					indices.push(6, 4, 7);
					indices.push(4, 7, 5);
					indices.push(7, 5, 8);
					uvtData = new Array();
					//这里是定义6各点原来应在的位置
					uvtData.push(0, 0);
					uvtData.push(0, 0.5);
					uvtData.push(0, 1);
					uvtData.push(0.5, 0);
					uvtData.push(0.5, 0.5);
					uvtData.push(0.5, 1);
					uvtData.push(1, 0);
					uvtData.push(1, 0.5);
					uvtData.push(1, 1);
					backLayer = new LSprite();
					backLayer.x=200;
					addChild(backLayer);
					backLayer.graphics.clear();
					backLayer.graphics.beginBitmapFill(bitmapData);
					backLayer.graphics.drawTriangles(vertices, indices, uvtData);
					
					//3d
					var i,j;
					var r=100;
					vertices = new Array();
					for(i=0;i<=cols;i++){
						for(j=0;j<=rows;j++){
							var angle = (90-180*j/rows)*Math.PI/180;
							var a = Math.sin(angle);
							if((90-180*j/rows)%90==0 && (90-180*j/rows)%180!=0)a=(90-180*j/rows)>0?1:-1;
							if((90-180*j/rows)%180==0)a=0;
							var sy =  -r*a;
							var sa = Math.cos(angle);
							if((90-180*j/rows)%180==0)sa=1;
							var sr =  Math.abs(r*sa);
							var angle2 = 360*(i+1)/cols;
							var b = Math.cos(angle2*Math.PI/180);
							if(angle2%360==0)b=1;
							else if(angle2%180==0)b=-1;
							var sx =  sr*b;
							vertices.push(sx, sy);
						}
					}
					indices = new Array();
					for(i=9;i<cols-1;i++){
						for(j=0;j<rows;j++){
							indices.push(i*(rows+1)+j,(i+1)*(rows+1)+j,i*(rows+1)+j+1);
							indices.push((i+1)*(rows+1)+j,i*(rows+1)+j+1,(i+1)*(rows+1)+j+1);
						}
					}
					uvtData = new Array();
					for(i=0;i<=cols;i++){
						for(j=0;j<=rows;j++){
							uvtData.push(i/cols, j/rows);
						}
						
					}
					backLayer = new LSprite();
					backLayer.x=450;
					backLayer.y=100;
					addChild(backLayer);
					backLayer.graphics.clear();
					backLayer.graphics.beginBitmapFill(earthBitmapData);
					backLayer.graphics.drawTriangles(vertices, indices, uvtData);
				}
			</script>
			
			
			
	</body>
</html>